package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.CuCustomerMapper;
import org.linlinjava.litemall.db.domain.CuCustomer;
import org.linlinjava.litemall.db.domain.CuCustomer.Column;
import org.linlinjava.litemall.db.domain.CuCustomerExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CuCustomerService {
    @Resource
    private CuCustomerMapper customerMapper;
    private Column[] columns = new Column[]{Column.customerName, Column.customerPhone, Column.customerGender, Column.customerBirth, Column.customerStatus};

//    public List<LitemallShop> query(Integer page, Integer limit, String sort, String order) {
//        LitemallShopExample example = new LitemallShopExample();
////        example.or().andDeletedEqualTo(false);
//        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
//            example.setOrderByClause(sort + " " + order);
//        }
//        PageHelper.startPage(page, limit);
//        return customerMapper.selectByExampleSelective(example, columns);
//    }
//
//    public List<LitemallShop> query(Integer page, Integer limit) {
//        return query(page, limit, null, null);
//    }
//
//    public LitemallShop findById(Integer id) {
//        return customerMapper.selectByPrimaryKey(id);
//    }

    public List<CuCustomer> querySelective(String customerName, String customerPhone, Integer page, Integer size, String sort, String order) {
        CuCustomerExample example = new CuCustomerExample();
        CuCustomerExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(customerName)) {
            criteria.andCustomerNameLike("%" + customerName + "%");
        }


        if (!StringUtils.isEmpty(customerPhone)) {
            criteria.andCustomerPhoneEqualTo(customerPhone);
        }


        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, size);
        return customerMapper.selectByExample(example);
    }
//
//    public int updateById(LitemallShop shop) {
//        return customerMapper.updateByPrimaryKeySelective(shop);
//    }
//
//    public void deleteById(Integer id) {
//        customerMapper.deleteByPrimaryKey(id);
//    }
//
//    public void add(LitemallShop shop) {
//        shop.setAddTime(LocalDateTime.now());
//        customerMapper.insertSelective(shop);
//    }
//
//    public List<LitemallShop> all() {
//        LitemallShopExample example = new LitemallShopExample();
////        example.or().andDeletedEqualTo(false);
//        return customerMapper.selectByExample(example);
//    }
}
